	package com.swust.log;

import org.apache.log4j.spi.Filter;
import org.apache.log4j.spi.LoggingEvent;


/**
 * @category 自定义log4jfilter
 * @Description 
 * @author hmilysean 
 * @date 2016年2月29日 上午9:27:27 
 * @version V0.1
 */
public class CustomerLogFilter extends Filter {  
	    boolean acceptOnMatch = false;  
	    private String levelMin;  
	    private String levelMax; 
	      
	    public String getLevelMin() {  
	        return levelMin;  
	    }  
	    
	    public void setLevelMin(String levelMin) {  
	        this.levelMin = levelMin;  
	    }  
	    
	    public String getLevelMax() {  
	        return levelMax;  
	    }  
	  
	  
	  
	    public void setLevelMax(String levelMax) {  
	        this.levelMax = levelMax;  
	    }  
	  
	  
	  
	    public boolean isAcceptOnMatch() {  
	        return acceptOnMatch;  
	    }  
	  
	  
	  
	    public void setAcceptOnMatch(boolean acceptOnMatch) {  
	        this.acceptOnMatch = acceptOnMatch;  
	    }  
	  
	  
	    public int decide(LoggingEvent lgEvent) {  
	        int inputLevel = lgEvent.getLevel().toInt();  
	          
	        if(inputLevel>=getLevel(levelMin) && inputLevel <= getLevel(levelMax)){  
	            return 0;  
	        }         
	          
	        return -1;  
	    }  
	      
	    private int getLevel(String level){  
	        level = level.toUpperCase();  
	        if(level.equals("MONEY")){  
	            return LevelType.MONEY.getType();  
	        }  
	        if(level.equals("OTHERAPI")){  
	            return LevelType.OTHERAPI.getType();  
	        } 
	        if(level.equals("INTERFACE")){  
	            return LevelType.INTERFACE.getType();  
	        } 
	        if(level.equals("OFF")){  
	            return LevelType.OFF.getType();  
	        }  
	        if(level.equals("FATAL")){  
	            return LevelType.FATAL.getType();  
	        }  
	        if(level.equals("ERROR")){  
	            return LevelType.ERROR.getType();  
	        }  
	        if(level.equals("INFO")){  
	            return LevelType.INFO.getType();  
	        }  
	        if(level.equals("WARN")){  
	            return LevelType.WARN.getType();  
	        }  
	        if(level.equals("DEBUG")){  
	            return LevelType.DEBUG.getType();  
	        }  
	        if(level.equals("ALL")){  
	            return LevelType.ALL.getType();  
	        }  
	        
	        return LevelType.OFF.getType();  
	    }  
	      
	    private static enum LevelType{  
	          
	        OFF(2147483647),  
	          
	        FATAL(50000),  
	        
	        OTHERAPI(45060),
	          
	        ERROR(40000),  
	        
	        MONEY(35050),
	          
	        INTERFACE(35000),
	        
	        WARN(30000),  
	          
	        INFO(20000),  
	          
	        DEBUG(10000),  
	          
	        ALL(-2147483648) 
	        
	        ;  
	        
	    	
	    	
	        int type;  
	          
	        public int getType() {  
	            return type;  
	        }  
	  
	        private LevelType(int type) {  
	            this.type = type;  
	        }  
	    }  
	  
	
	}
